import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { CudTableService } from 'app/public/serve/cud-table/cud-table.service';
import { Service } from '../../../server/server';
import { appProjectUrl } from '../project.url';
import { project } from '../project.data';
import { HintsService } from '../../../public/serve/hints/hints.service';
import { InitService } from '../../../public/serve/init/init.service';
declare var $:any;

@Component({
  selector: 'app-project-setting',
  templateUrl: './project-setting.component.html',
  styleUrls: ['./project-setting.component.css']
})
export class ProjectSettingComponent implements OnInit {

  @Output() onSubmit = new EventEmitter<void>();

  total      : number = 0;
  naturalNum : number = 0;
  pageNo : number = 1;
  pageSize : number = 20;

  tabDetailVal : Array<object>;
  details: object = {};
  @Input() synonymName :any = '';

  isSelectAll : boolean = false;
  isChose : boolean = false;
  searchData : any = '';

  constructor(
    private server: Service,
    public request: CudTableService,
    private hintsService: HintsService,
    public initService: InitService
  ) { 
    
  }

  ngOnInit() {
  }

  /**
   * 详情
   */
  _details(info: object){
    this.details = info;
  }

  /**
   * 查询已指定项目的产品列表
   */
  _getHasProjectProductList(){
    let data = this._tableDetailData();
    this.request.postRequest(this.server.baseUrl +appProjectUrl.getHasProjectProductList,data).then((res:any) => {
      if (res.result_code === '0000') {
        this.tabDetailVal = res.result;
        this.total = res.length;
        this.naturalNum = project.pagination.naturalNum;
      }else{
        this.hintsService.messages(res.message,res.result_code);
      }

      return;
    })
    .catch((err: any)=>{
      this.hintsService.messages("error","error");
      return;
    });
  }

  /**
   * 搜索
   * @param val
   */
  _retrieval(val:string){
    this.searchData = val.trim();
    this._getHasProjectProductList();
  }

  /**
   * 分页
   * @param pagination 
   */ 
  _pagination(pagination: Array<any>) {
    this.pageNo = pagination[0].pageNumber;
    this.pageSize   = pagination[0].pageSize;
    this.naturalNum = (this.pageNo - 1) * this.pageSize;
    this._getHasProjectProductList();
  }

  //查询参数
  private _tableDetailData(){
    return {
      token         : project.retrieval.token,
      pageNo        : this.pageNo,
      pageSize      : this.pageSize,
      queryCriteria : this.searchData,
      projectId     : this.details['projectId'],
    }
  }

}
